<template>
  <div class="onething">
    <div class="search-area">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
        <CascaderSelect
          :values="queryParams.dept"
          :varient="'energy'"
          :filterable="true"
          size="small"
          placeholder="个例搜索用能部门"
          @input="handleChange"
        ></CascaderSelect>
      </el-form>
    </div>
    <el-row class="row-inline" :gutter="10">
      <el-col
        :span="5"
        class="row-item"
        v-for="(item, index) in stepArr"
        :key="index"
      >
        <div class="item-card" @click="handleShow(item)">
          <img :src="item.logo" alt="" />
          <div class="card-left">
            <span>{{ item.name }}</span>
            <div class="card-left-bottom">
              <animate-number
                from="0"
                :to="item.num"
                :key="item.num"
                :class="['an-number', 'color' + index]"
                v-if="item.num <= 9999 && !mini.test(item.num)"
              ></animate-number>
              <el-tooltip
                v-if="item.num > 9999"
                :content="item.num.toString()"
                placement="top"
                effect="light"
                :popper-class="'num-tooltip num-tooltip' + index"
              >
                <span :class="['an-number-ex', 'color' + index]">9999+</span>
              </el-tooltip>
              <span
                v-if="item.num <= 9999 && mini.test(item.num)"
                :class="['an-number', 'color' + index]"
              >
                {{ item.num }}
              </span>
              <span class="unit">{{ item.unit }}</span>
            </div>
          </div>
        </div>
        <!-- <img
          class="line"
          v-if="index != 4 && screenWidth > 1860"
          src="@/assets/images/index/index-arrow.png"
          alt=""
        /> -->
      </el-col>
    </el-row>
    <popCom
      :visible.sync="visible"
      :type="typeChose"
      @close="close"
      :deptID="deptID"
      :stepType="stepType"
    />
  </div>
</template>

<script>
import popCom from "@/views/home/onething/components/pop.vue";
import CascaderSelect from "@/components/Select/CascaderSelect";
export default {
  name: "onething",
  components: {
    popCom,
    CascaderSelect,
  },
  props: {
    dataArr: {
      type: Array,
      default: [],
    },
  },
  data() {
    return {
      screenWidth: "", // 屏幕宽度
      screenHeight: "", // 屏幕高度
      mini: /[.]/, // 小数正则
      visible: false,
      deptID: null,
      typeChose: 0,
      queryParams: {
        dept: [],
      },
      deptArr: [],
      stepType: 0,
      stepArr: [
        {
          name: "综合能耗",
          color: "#10B767",
          logo: require("@/assets/images/index/index-step-1.png"),
          id: "",
          num: 0,
          type: 1,
          unit: "kgce",
        },
        {
          name: "额度总和",
          color: "#10B767",
          logo: require("@/assets/images/index/index-step-2.png"),
          id: "",
          num: 0,
          type: 2,
          unit: "kgce",
        },
        {
          name: "额度超支",
          color: "#10B767",
          logo: require("@/assets/images/index/index-step-3.png"),
          id: "",
          num: 0,
          type: 3,
          unit: "kgce",
        },
        {
          name: "建议措施",
          color: "#10B767",
          logo: require("@/assets/images/index/index-step-4.png"),
          id: "",
          num: 0,
          type: 4,
          unit: "条",
        },
        {
          name: "碳中和",
          color: "#10B767",
          logo: require("@/assets/images/index/index-step-5.png"),
          id: "",
          num: 0,
          type: 5,
          unit: "kgce",
        },
      ],
    };
  },
  created() {
    // this.screenWatcher();
  },
  watch: {
    dataArr: {
      handler(val) {
        if (val) {
          this.stepDatadeal();
        }
      },
      deep: false,
      immediate: true,
    },
  },
  mounted() {
    this.screenWatcher();
  },
  methods: {
    // 浏览器视窗大小监控
    screenWatcher() {
      this.screenWidth = document.body.clientWidth;
      this.screenHeight = document.body.clientHeight;
      window.onresize = () => {
        // console.log(111);
        return (() => {
          this.screenWidth = document.body.clientWidth;
          this.screenHeight = document.body.clientHeight;
        })();
      };
    },
    stepDatadeal() {
      // console.log(this.dataArr, 9987);
      this.dataArr.map((item, index) => {
        this.stepArr[index].num = this.dataArr[index];
      });
    },
    handleChange(value) {
      if (value && value.length > 0) {
        this.queryParams.dept = value;
        this.deptID = this.queryParams.dept[this.queryParams.dept.length - 1];
      } else {
        this.queryParams.dept = null;
        this.deptID = null;
      }
      this.typeChose = 1;
      setTimeout(() => {
        this.visible = true;
      }, 100);
    },
    handleShow(item) {
      this.stepType = item.type;
      this.typeChose = 0;
      setTimeout(() => {
        this.visible = true;
      }, 100);
    },
    close() {
      this.queryParams.dept = [];
      this.visible = false;
    },
  },
};
</script>

<style lang="scss">
.num-tooltip {
  border-color: rgb(245, 238, 238) !important;
  font-weight: 800;
  font-size: 14px;
}

.el-tooltip__popper[x-placement^="top"].num-tooltip .popper__arrow {
  border-top-color: rgb(245, 238, 238) !important;
}
.el-tooltip__popper[x-placement^="top"].num-tooltip .popper__arrow::after {
  // border-top-color: #10B767 !important; /*设置指向箭头的颜色*/
}
.num-tooltip0 {
  color: #10b767;
}
.num-tooltip1 {
  color: #10b767;
}
.num-tooltip2 {
  color: #10b767;
}
.num-tooltip3 {
  color: #10b767;
}
.num-tooltip4 {
  color: #10b767;
}
</style>

<style lang="scss" scoped>
.onething {
  width: 100%;
  height: 180px;
  position: relative;
  .search-area {
    position: absolute;
    top: -50px;
    right: 50px;
  }
  .row-inline {
    width: 100%;
    min-width: 1602px;
    height: 100%;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    .row-item {
      display: flex;
      align-items: center;
      .item-card {
        width: 100%;
        cursor: pointer;
        display: flex;
        padding: 16px;
        box-sizing: border-box;
        border-radius: 10px;
        box-shadow: 0px 2px 8px 4px rgba(21, 61, 145, 0.04);
        z-index: 100;
        img {
          width: 100px;
          height: 100px;
        }
        .card-left {
          margin-left: 5px;
          height: 100px;
          display: flex;
          flex-direction: column;
          justify-content: space-around;
          .card-left-bottom {
            width: 100%;
            display: flex;
            align-items: baseline;
            .unit {
              margin-left: 5px;
              font-family: PingFangSC-Semibold, PingFang SC;
              font-size: 14px;
              font-weight: 600;
              color: rgba(0, 0, 0, 0.85);
              line-height: 20px;
            }
          }
          span {
            font-family: PingFangSC-Semibold, PingFang SC;
            font-size: 16px;
            font-weight: 600;
            color: rgba(0, 0, 0, 0.85);
            line-height: 22px;
          }
          .an-number {
            // width: 100px;
            font-family: PingFangSC-Semibold, PingFang SC;
            font-size: 40px;
            font-weight: bold;
            line-height: 62px;
          }
          .an-number-ex {
            // width: 100px;
            font-family: PingFangSC-Semibold, PingFang SC;
            font-size: 36px;
            font-weight: bold;
            line-height: 56px;
          }
          // .big-num {
          //   /*1. 先强制一行内显示文本*/
          //   white-space: nowrap;
          //   /*2. 超出的部分隐藏*/
          //   overflow: hidden;
          //   /*3. 文字用省略号替代超出的部分*/
          //   text-overflow: ellipsis;
          // }
          .color0 {
            color: #10b767;
          }
          .color1 {
            color: #10b767;
          }
          .color2 {
            color: #10b767;
          }
          .color3 {
            color: #10b767;
          }
          .color4 {
            color: #10b767;
          }
        }
      }
    }
  }
  .line {
    margin-left: 5px;
    width: 80px;
    height: 23px;
    z-index: 98;
  }
}
</style>
